package com.sq.partner.manager.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.sq.partner.manager.dao.OutboundCardApplyDao;
import com.sq.partner.manager.mybatis.model.FacadePayment;
import com.sq.partner.manager.mybatis.model.GatewayUser;
import com.sq.partner.manager.mybatis.model.OutboundCardApply;
import com.sq.partner.manager.util.Page;

/**
 * 卡单出库申请Dao实现
 * 
 * SQ
 *
 */
@Repository
public class OutboundCardApplyDaoImpl extends BaseDaoImpl implements
        OutboundCardApplyDao {

    @SuppressWarnings("unchecked")
    @Override
    public Page<OutboundCardApply> queryOutboundList(
            Page<OutboundCardApply> page) throws Exception {
        Map<String, Object> paramMap = page.getMap();
        page.setTotal((Integer) this.query("queryOutboundCardApplyCount",
                paramMap));
        page.setData((List<OutboundCardApply>) this.queryList(
                "queryOutboundCardApplyList", paramMap));
        return page;
    }

    @SuppressWarnings("unchecked")
    @Override
    public Page<OutboundCardApply> queryCardInfoByCommamtId(
            Page<OutboundCardApply> page) throws Exception {
        Map<String, Object> paramMap = page.getMap();
        page.setData((List<OutboundCardApply>) this.queryList(
                "queryCardInfoListByCommamtId", paramMap));
        return page;
    }

    /**
     * 根据条件分页查询选择出库的多条卡单信息
     * 
     * @param applyinfo
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @Override
    public Page<OutboundCardApply> queryOutboundAppliedList(
            Page<OutboundCardApply> page) throws Exception {
        Map<String, Object> paramMap = page.getMap();
        page.setData((List<OutboundCardApply>) this.queryList(
                "queryOutboundAppliedList", paramMap));
        return page;
    }

    // /**
    // * 查找方案号
    // * @param name
    // * @return
    // * @throws Exception
    // */
    // @Override
    // public String queryPlanNo(String name) throws Exception{
    // Map<String,Object> paramMap = new HashMap<String,Object>();
    // paramMap.put("name",name);
    // return (String)this.query("queryPlanNo", paramMap);
    //
    // }

    // @Override
    // public boolean updatePlanNo(String name,String planNo) throws Exception{
    // Map<String,Object> paramMap = new HashMap<String,Object>();
    // paramMap.put("name",name);
    // paramMap.put("planNo", planNo);
    // boolean flag= this.update("updatePlanNo", paramMap);
    //
    // return flag;
    // }

    @Override
    public boolean updateStatusAndCommamtId(HashMap<String, Object> paramMap)
            throws Exception {
        return this.update("updateStatusAndCommamtId", paramMap);
    }

    @Override
    public Integer queryCountMax(HashMap<String, Object> paramMap)
            throws Exception {
        return (Integer) this.query("queryCountMax", paramMap);
    }

    @Override
    public boolean updateStatusByCommamtId(HashMap<String, Object> paramMap)
            throws Exception {
        return this.update("updateStatusByCommamtId", paramMap);
    }

    @Override
    public boolean updateCancelStatusByCommamtId(
            HashMap<String, Object> paramMap) throws Exception {
        return this.update("updateCancelStatusByCommamtId", paramMap);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<String> getCardNoList(String commamtId) throws Exception {
        return (List<String>) this.queryList("getCardNoList", commamtId);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<OutboundCardApply> queryUpdateList(
            HashMap<String, Object> paramMap) throws Exception {
        return (List<OutboundCardApply>) this.queryList("queryUpdateList",
                paramMap);
    }
    @Override
    public String findFacadePaymentBystagNo(String stagNo) throws Exception{
        return (String)query("queryFacadePaymentBystagNo", stagNo);
    }
    @Override
    public void saveFacadePayment(FacadePayment payment) throws Exception{
        add("insertFacadePayment", payment);
    }
    @Override
    public FacadePayment getFacadePaymentByTransNo(String transNo) throws Exception {
        // TODO Auto-generated method stub
        return (FacadePayment)query("queryFacadePaymentById",transNo);
    }
    @Override
    public boolean updateFacadePayment(FacadePayment payment) throws Exception{
        return update("updateFacadePaymentNotNull", payment);
    }
    @Override
    public FacadePayment queryPayment(HashMap<String,String> map) throws Exception{
        return (FacadePayment)query("queryFacadePaymentByMap",map);
    }
    
    /**
     * 根据出库ID查找出库人数字工号
     * @param commamtId
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, String> getEmployeeNoByCommamtId(String commamtId) throws Exception {
        return (Map<String, String>)this.query("queryEmployeeNoByCommamtId", commamtId);
    }
}
